package com.dycx.api.controller.manage.user;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.common.RestResponse;
import com.dycx.user.dto.CommentDTO;
import com.dycx.user.service.CommentService;
import com.dycx.user.vo.CommentVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 评论(Comment)表控制层
 *
 * @author wuzongbin
 * @since 2023-12-29 10:53:24
 */
@RestController
@RequestMapping(value = "/manage/user/comment")
public class CommentController {
    /**
     * 服务对象
     */
    @Resource
    private CommentService commentService;

    /**
     * 分页

     **/
    @PostMapping("/getPage")
    public RestResponse<Page<CommentVO>> getPage(@RequestBody CommentDTO dto) {
        return RestResponse.success(commentService.getPage(dto));
    }

    /**
     * 查询详细

     **/
    @GetMapping("/load")
    public RestResponse<CommentVO> load(Integer commentId) {
        return RestResponse.success(commentService.load(commentId));
    }

    /**
     * 添加

     **/
    @PostMapping("/create")
    public RestResponse<Boolean> create(@RequestBody @Valid CommentDTO dto) {
        return commentService.create(dto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改

     **/
    @PostMapping("/edit")
    public RestResponse<Boolean> edit(@RequestBody @Valid CommentDTO dto) {
        return commentService.edit(dto) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 刪除

     **/
    @GetMapping("/delete")
    public RestResponse<Boolean> delete(Integer commentId) {
        return commentService.delete(commentId) ? RestResponse.success() : RestResponse.fail();
    }
}

